package com.threegroup.admin.controller;


import com.threegroup.admin.annotation.AuthorityVerify.AuthorityVerify;
import com.threegroup.admin.service.OrderDetailService;
import com.threegroup.common.dto.OrderDetailDTO;
import com.threegroup.common.dto.OrderDetailPageDTO;
import com.threegroup.common.entity.OrderDetailEntity;
import com.threegroup.common.utils.Result;
import com.threegroup.common.vo.OrderDetailInfoVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
public class OrderDetailController {

  @Resource
  private OrderDetailService orderDetailService;

  //添加订单明细
  @AuthorityVerify("takeout:orderdetail:save")
  @PostMapping("takeout/orderdetail")
  public Result addOrderDetail(@RequestBody OrderDetailDTO orderDetailDTO) {
    Result result = orderDetailService.addOrderDetail(orderDetailDTO,null);
    return result;
  }

  //修改订单明细
  @AuthorityVerify("takeout:orderdetail:update")
  @PutMapping("takeout/orderdetail")
  public Result updeteOrderDetail(@RequestBody OrderDetailDTO orderDetailDTO) {
    Result result = orderDetailService.updeteOrderDetail(orderDetailDTO);
    return result;
  }

  //删除订单明细
  @AuthorityVerify("takeout:orderdetail:delete")
  @DeleteMapping("takeout/orderdetail")
  public Result deleteOrderDetail(@RequestBody Long[] ids) {
    Result result = orderDetailService.deleteOrderDetail(ids);
    return result;
  }

  //查询该订单明细
  @AuthorityVerify("takeout:orderdetail:info")
  @GetMapping("takeout/orderdetail/{id}")
  public Result<OrderDetailEntity> selectOrderDetail(@PathVariable("id") Integer id){
    Result result = orderDetailService.selectOrderDetail(id);
    return result;
  }

  //查询根据orderId查多个订单明细信息
  @AuthorityVerify("takeout:orderdetail:info")
  @GetMapping("takeout/orderdetail/detailInfo/{id}")
  public Result<OrderDetailInfoVo> selectOrderDetailInfoVo(@PathVariable("id") Long OrderId){
    Result result = orderDetailService.selectOrderDetailInfoVo(OrderId);
    return result;
  }

  //分页查询多个订单明细
  @AuthorityVerify("takeout:orderdetail:page")
  @GetMapping("takeout/orderdetail/page")
  public Result selectOrderDetailList(OrderDetailPageDTO orderDetailPageDTO){
    Result result = orderDetailService.selectOrderDetailList(orderDetailPageDTO);
    return result;
  }
}
